import pymysql


class MyDB():
    def __init__(self):
        self.con = pymysql.connect(
            user="root",
            password="Admin@888",
            host="192.168.1.9",
            database="brtc_api",
            port=3306,
            autocommit=True
        )
        #创建游标
        self.cursor = self.con.cursor()

    def get_one(self, sql):
        self.cursor.execute(sql)
        return self.cursor.fetchone()

    def execute(self, sql):
        self.cursor.execute(sql)
        self.con.commit()
        # return True

    #释放数据库连接
    def __del__(self):
        self.cursor.close()
        self.con.close()


myDB = MyDB()
